// cloudfunctions/removeCartItem/index.js
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database()

exports.main = async (event, context) => {
  const { cartItemId } = event

  if (!cartItemId) {
    return {
      success: false,
      message: '参数缺失'
    }
  }

  try {
    // 删除购物车项
    await db.collection('carts').doc(cartItemId).remove()
    return {
      success: true
    }
  } catch (err) {
    return {
      success: false,
      message: '删除失败',
      error: err
    }
  }
}
